package com.hotel.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotel.mapper.RightsMapper;
import com.hotel.pojo.Rights;
import com.hotel.service.RightsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author by LuJinRong
 * @date 2021/7/25。
 * @time 18:02。
 */
@Service
public class RightsServiceImpl implements RightsService {

    @Autowired
    private RightsMapper rightsMapper;

    @Override
    public List<Rights> getRightsList() {
        QueryWrapper<Rights> queryWrapper = new QueryWrapper();
        queryWrapper.eq("parent_id", 0);
        List<Rights> oneList =  rightsMapper.selectList(queryWrapper);
        //2.查询1级下边的二级list集合
        for (Rights rights : oneList){
            queryWrapper.clear();
            queryWrapper.eq("parent_id", rights.getId());
            List<Rights> children =  rightsMapper.selectList(queryWrapper);
            //查询子级之后，将数据赋值给父级，实现嵌套查询
            rights.setChildren(children);
        }
        return oneList;
    }
}
